Imports PTT.CarRes.Data

Public Class ClassQueryInvCarSize
    Public Function Add(ByVal InvCarSize As QueryInvCarSize, ByVal Strconn As String) As Boolean
        Dim ClsInvCarSize As New ClassInvCarSize
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvCarSize.ConnectionOpen(Strconn)
        Dim ret As Boolean = False
        With ClsInvCarSize
            .SizeId = InvCarSize.SizeId
            .SizeName = InvCarSize.SizeName
            .SizeStatus = InvCarSize.SizeStatus
            ret = .USP_Save(Conn)
        End With
        ClsInvCarSize.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Edit(ByVal InvCarSize As QueryInvCarSize, ByVal Strconn As String) As Boolean
        Dim ClsInvCarSize As New ClassInvCarSize
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvCarSize.ConnectionOpen(Strconn)
        Dim ret As Boolean = False
        With ClsInvCarSize
            .SizeId = InvCarSize.SizeId
            .Load(Conn)
            .SizeName = InvCarSize.SizeName
            .SizeStatus = InvCarSize.SizeStatus
            ret = .USP_Update(Conn)
        End With
        ClsInvCarSize.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Delete(ByVal InvCarSize As QueryInvCarSize, ByVal Strconn As String) As Boolean
        Dim ClsInvCarSize As New ClassInvCarSize
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvCarSize.ConnectionOpen(Strconn)
        Dim ret As Boolean = False
        With ClsInvCarSize
            .SizeId = InvCarSize.SizeId
            .Load(Conn)
            ret = .USP_Delete(Conn)
        End With
        ClsInvCarSize.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Search(Optional ByVal ParaSizeId As String = "", _
    Optional ByVal ParaSizeName As String = "", _
    Optional ByVal ParaSizeStatus As String = "", Optional ByVal Strconn As String = "") As QueryInvCarSizes
        Dim ClsInvCarSize As New ClassInvCarSize
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvCarSize.ConnectionOpen(Strconn)
        Dim ret As QueryInvCarSizes = Nothing
        Dim str As String = ""
        Dim Condition As String = ""
        str &= " Select * from InvCarSize"
        If ParaSizeId & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(SizeId = " & ParaSizeId & ")"
        End If
        If ParaSizeName & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(SizeName like '%" & ParaSizeName & "%')"
        End If
        If ParaSizeStatus & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(SizeStatus like '%" & ParaSizeStatus & "%')"
        End If

        If Condition & "" <> "" Then
            str &= " where "
            str &= Condition
        End If
        Dim ds As DataSet
        With ClsInvCarSize
            ds = .BindData(Conn, , , str)
            If Not ds Is Nothing Then
                Dim i As Integer
                Dim results As New QueryInvCarSizes

                Try
                    For i = 0 To ds.Tables(0).Rows.Count - 1
                        With ds.Tables(0).Rows(i)

                            results.Add(New QueryInvCarSize( _
                              .Item("SizeId") & "", _
                              .Item("SizeName") & "", _
                              .Item("SizeStatus") & "" _
                            ))
                        End With
                    Next
                    ret = results
                Catch ex As Exception
                    Return Nothing
                    'Throw New DALException(ex.Message)
                End Try
            End If
        End With
        ClsInvCarSize.ConnectionClose(Conn)
        Return ret
    End Function
    Public Function Load(Optional ByVal ParaSizeId As String = "", Optional ByVal Strconn As String = "") As QueryInvCarSizes
        Dim ClsInvCarSize As New ClassInvCarSize
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvCarSize.ConnectionOpen(Strconn)
        Dim ret As QueryInvCarSizes = Nothing
        Dim str As String = ""
        Dim Condition As String = ""
        str &= " Select * from InvCarSize"
        If ParaSizeId & "" <> "" Then
            If Condition & "" <> "" Then Condition &= " and "
            Condition &= "(SizeId = " & ParaSizeId & ")"
        End If

        If Condition & "" <> "" Then
            str &= " where "
            str &= Condition
        Else
            Return Nothing
            Exit Function
        End If
        Dim ds As DataSet
        With ClsInvCarSize
            ds = .BindData(Conn, , , str)
            If Not ds Is Nothing Then
                Dim i As Integer
                Dim results As New QueryInvCarSizes

                Try
                    For i = 0 To ds.Tables(0).Rows.Count - 1
                        With ds.Tables(0).Rows(i)

                            results.Add(New QueryInvCarSize( _
                              .Item("SizeId") & "", _
                              .Item("SizeName") & "", _
                              .Item("SizeStatus") & "" _
                            ))
                        End With
                    Next
                    ret = results
                Catch ex As Exception
                    Return Nothing
                    'Throw New DALException(ex.Message)
                End Try
            End If
        End With
        ClsInvCarSize.ConnectionClose(Conn)
        Return ret
    End Function
End Class